package com.chenl.provider.题目;

import lombok.SneakyThrows;

import java.math.BigDecimal;
import java.util.concurrent.*;

public class Day4 {
    @SneakyThrows
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        CyclicBarrier cyclicBarrier=new CyclicBarrier(3);
        executorService.execute(()->{
            try {
                cyclicBarrier.await();
                System.out.println(123);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            } catch (BrokenBarrierException e) {
                throw new RuntimeException(e);
            }
        });
//        executorService.execute(()->{
//            try {
//                cyclicBarrier.await();
//                System.out.println(123);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            } catch (BrokenBarrierException e) {
//                throw new RuntimeException(e);
//            }
//        });
        cyclicBarrier.await();
        long end = System.currentTimeMillis();
        executorService.shutdown();
        System.out.println(BigDecimal.valueOf(end).subtract(BigDecimal.valueOf(start)).divide(BigDecimal.valueOf(1000))+"秒");
    }



}
